package edu.uclmgmu.bacteriosec.domain.data;

import java.io.IOException;
import java.util.Vector;

import edu.uclmgmu.bacteriosec.aspects.common.FilesStore;

public class MethodCatched {
	private String name;
	private Vector<TestCaseExecuted> testCases;
	private Vector<CallResult> callResults;
	
	public MethodCatched(String name) {
		this.name=name;
		this.testCases=new Vector<TestCaseExecuted>();
		this.callResults=new Vector<CallResult>();
	}
	
	public void add(String testCaseName) throws IOException {
		int noc=FilesStore.readNumberOfCalls(this.name, testCaseName);
		int from=FilesStore.readStartingCall(this.name, testCaseName);
		int to=FilesStore.readEndCall(this.name, testCaseName);
		TestCaseExecuted tce=new TestCaseExecuted(testCaseName);
		tce.setNumberOfCalls(noc);
		tce.setStartCall(from);
		tce.setEndCall(to);
		this.testCases.add(tce);
	}
	
	public void add(TestCaseExecuted testCase) {
		this.testCases.add(testCase);
	}

	public String getName() {
		return this.name;
	}

	public Vector<TestCaseExecuted> getTestCases() {
		return this.testCases;
	}

	public int getNumberOfCalls() {
		int result=0;
		for (TestCaseExecuted tce : this.testCases)
			result+=tce.getNumberOfCalls();
		return result;
	}
	
	@Override
	public String toString() {
		return this.name;
	}

	public void loadTestCaseNames(Vector<String> testCaseNames) {
		for (TestCaseExecuted tce : this.testCases)
			if (!testCaseNames.contains(tce.getName()))
				testCaseNames.add(tce.getName());
	}
	
	public void loadTestCases(Vector<TestCaseExecuted> testCases) {
		for (TestCaseExecuted tce : this.testCases)
			if (!testCases.contains(tce))
				testCases.add(tce);
	}

	public void add(CallResult cr) {
		this.callResults.add(cr);
	}

	public Vector<CallResult> getCallResults() {
		return callResults;
	}

	public void loadCallResults(Vector<CallResult> result) {
		for (CallResult cr : this.callResults) {
			result.add(cr);
		}
	}
}
